# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:       加一
# Name:         demo5.05
# Description:  分别使用一对大括号“{}”、命名格式化参数和顺序格式化参数3种方式格式
#               化字符串
# Author:       加一
# Date:         2019/2/27
#-------------------------------------------------------------------------------

# 包含了2个空的大括号，format方法需要按顺序指定格式化参数值
s1 = "Today is{}， the temperature is {} degrees."
# format方法的第1个参数值对应S1的第一对大括号，第2个参数值对应s1的第2对大括号。
print(s1.format("Saturday",24))

# 包含了2个命名格式化参数
s2 = "Today is {week}, the temperature is {degree} degrees."
print(s2.format(degree = 22, week ="Sunday"))

# 混合了顺序格式化参数和关键字格式化参数两种方式。
s3 = "Today is {week}, {}，the {} temperature is {degree} degrees."
print(s3.format("aaaaa", 12345, degree = 22, week ="Sunday"))

# 为顺序格式化参数制定了从format方法获取参数值的顺序
s4 = "Today is {week}, {1}，the {0} temperature is {degree} degrees."
print(s4.format("aaaaa", 12345, degree = 22, week ="Sunday"))

fullname = ["Bill", "Gates"]
print("Mr {name[1]}".format(name = fullname))

import math
s5 = "The {mod.__name__} module defines the value {mod.pi} for PI"
print(s5.format(mod = math))